package at.fhooe.engine.time;

import at.fhooe.engine.pandora.Game;

public class FPSCounter {
	
	private boolean m_active;
	private double m_time;
	private int m_counter;
	private int m_bufferdCounter;
	
	public FPSCounter(boolean active) {
		m_active = active;
		initValues();
	}
	
	private void initValues() {
		m_time = 0;
		m_counter = 0;
		m_bufferdCounter = -1;
	}
	
	public void update() {
		if(!m_active) {
			return;
		}
		m_time += Game.getInstance().getDeltaTime();
		if(m_time > 1.0) {
			m_counter++;
			m_bufferdCounter = m_counter;
			m_counter = 0;
			m_time = 0;
		} else {
			m_counter++;
		}
	}
	
	public int getBufferdCounter() {
		return m_bufferdCounter;
	}

	public boolean isActive() {
		return m_active;
	}

	public void turnOn() {
		m_active = true;
	}
	
	public void turnOff() {
		m_active = false;
		initValues();
	}
}
